﻿package com.eitb.programas.streamingUefa{
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	import flash.media.*;
	import flash.utils.*;
	import flash.net.*;
	import flash.geom.*;

	import org.openvideoplayer.net.*;
	import org.openvideoplayer.events.*;

	import com.eitb.literales.*;
	import com.eitb.bitmaps.*;
	import com.eitb.programas.*;
	import com.eitb.properties.*;
	import com.eitb.programas.streamingUefa.literales.*;
	import com.eitb.programas.streamingUefa.botones.*;

	public class DialogoStreamingUefa extends Sprite implements IVistaStreamingUefa {
		public static  const VIDEO_SIZE:Point = new Point(407,244.5);
		public static  const VIDEO_POSITION:Point = new Point(96.6,79.25);

		private var cStreaming:IControladorStreamingUefa;
		// UI elements
		private var video:Video;
		private var bMaxMin:MovieClip;
		private var volumeSlider:MovieClip;
		private var volumeIcon:MovieClip;
		private var timeDisplay:TextField;
		private var bufferingDisplay:TextField;
		private var statusDisplay:TextField;
		private var background:Bitmap;

		private var logo:Bitmap;

		public function DialogoStreamingUefa():void {
		}

		public function initControladorStreaming(cStreaming:IControladorStreamingUefa):void {
			this.cStreaming = cStreaming;
		}
		public function setVisible(mostrar:Boolean):void {
			this.visible = mostrar;
		}
		public function initStage(stageProps:StageProperties):void {
			this.stage.align=stageProps.align;
			this.stage.scaleMode=stageProps.scaleMode;
			this.stage.stageWidth = stageProps.width;
			this.stage.stageHeight = stageProps.height;
			this.stage.addEventListener(Event.RESIZE, this.cStreaming.resizeHandler);
		}

		public function initBackground(bitmap:Bitmap, size:Point):void {
			this.background = bitmap;
			this.background.x = 0;
			this.background.y = 0;
			this.background.width = size.x;
			this.background.height = size.y;
		}
		public function initLogo(bitmap:Bitmap):void {
			this.logo = bitmap;
			this.logo.x=523;
			this.logo.y=331;
		}

		public function initMaximizeButton():void {
			this.bMaxMin=new BotonMaximizar;
			this.bMaxMin.enabled=true;
			this.bMaxMin.x=23;
			this.bMaxMin.y=340;

			this.bMaxMin.addEventListener(MouseEvent.CLICK, this.cStreaming.doMaximizeMinimize);
			
		}
		public function initVideo(formato:String):void {
			this.video=new Video(480,288);
			this.video.x=23;
			this.video.y=90;
			this.video.deblocking= 5;
			this.video.smoothing = true;
			
			this.video.addEventListener(MouseEvent.CLICK, this.cStreaming.doMaximizeMinimize);
		}

		public function initVolumeSlider():void {
			this.volumeSlider=new VolumeSlider();
			this.volumeSlider.x=221;
			this.volumeSlider.y=346;
			this.volumeSlider.addEventListener(MouseEvent.CLICK, this.cStreaming.volumeHandler);
			this.initVolumeIcon(this.volumeSlider.barra);
		}
		
		public function initVolumeIcon(barra:MovieClip):void {
			this.volumeIcon=new VolumeIcon();
			this.volumeIcon.initBarra(barra);
			this.volumeIcon.x=357;
			this.volumeIcon.y=346;
			this.volumeIcon.addEventListener(MouseEvent.CLICK, this.cStreaming.volumeHandler);
		}
		
		public function initTimeDisplay(formato:String, format:TextFormat):void {
			this.timeDisplay=new TextField  ;
			this.timeDisplay.x=425;
			this.timeDisplay.y=348;
			this.timeDisplay.width=56;
			this.timeDisplay.height=23;
			this.timeDisplay.defaultTextFormat=format;
		}
		public function initBufferingDisplay(formato:String, format:TextFormat, text:String):void {
			this.bufferingDisplay=new TextField  ;
			this.bufferingDisplay.x=86;
			this.bufferingDisplay.y=348;
			this.bufferingDisplay.width=124;
			this.bufferingDisplay.height=23;
			this.bufferingDisplay.defaultTextFormat=format;
			this.bufferingDisplay.text=text;
		}
		public function initStatusDisplay(formato:String, format:TextFormat, text):void {
			this.statusDisplay=new TextField  ;
			this.statusDisplay.x=23;
			this.statusDisplay.y=376;
			this.statusDisplay.width=452;
			this.statusDisplay.height=34;
			this.statusDisplay.defaultTextFormat=format;
			this.statusDisplay.multiline=true;
			this.statusDisplay.wordWrap=true;
			this.statusDisplay.text=text;
		}

		public function addChildrens():void {
			addChild(this.background);
			addChild(this.bMaxMin);
			addChild(this.logo);
			addChild(this.volumeSlider);
			addChild(this.volumeIcon);
			addChild(this.timeDisplay);
			addChild(this.bufferingDisplay);
//			addChild(this.statusDisplay);
			addChild(this.video);
		}
		// VISTA STREAMING
		public function showElements(mostrar:Boolean):void {
			try {
				this.background.visible=mostrar;
				this.bMaxMin.visible=mostrar;
				this.logo.visible = mostrar;
				this.volumeSlider.visible=mostrar;
				this.volumeIcon.visible=mostrar;
				this.timeDisplay.visible=mostrar;
				this.bufferingDisplay.visible=mostrar;
//				this.statusDisplay.visible=mostrar;
			} catch (error:Error) {
			}
		}
		public function getDisplayState():String {
			return this.stage.displayState;
		}
		public function setDisplayState(state:String):void {
			this.stage.displayState = state;
		}
		public function getStageSize():Point {
			return new Point(this.stage.stageWidth,this.stage.stageHeight);
		}
		public function dispatchStageEvent(event:Event):Boolean {
			return this.stage.dispatchEvent(event);
		}
		public function fitScreen():void {
			this.stage.dispatchEvent(new Event(Event.RESIZE));
		}
		public function setVideoLocation(point:Point):void {
			this.video.x = point.x;
			this.video.y = point.y;
		}
		public function setVideoSize(point:Point):void {
			this.video.width = point.x;
			this.video.height = point.y;
		}
		public function attachVideoNetStream(ns:NetStream):void {
			this.video.attachNetStream(ns);
		}
		public function setStatusDisplayText(text:String):void {
			this.statusDisplay.text = text;
		}
		public function setVolumenSliderEnabled(enabled:Boolean):void {
			this.volumeSlider.enabled = enabled;
		}
		public function setVolumenIconEnabled(enabled:Boolean):void {
			this.volumeIcon.enabled = enabled;
		}
		public function setTimeDisplayText(text:String):void {
			this.timeDisplay.text = text;
		}
		public function setBufferDisplayVisible(visible:Boolean):void {
			this.bufferingDisplay.visible = visible;
		}
		public function setBufferDisplayText(text:String):void {
			this.bufferingDisplay.text = text;
		}
		public function setBotonMaxMinEnabled(enabled:Boolean):void {
			this.bMaxMin.enabled = enabled;
		}
		public function getVolumen():Number {
			return this.volumeSlider.getVolumen();
		}
		// VISTA STREAMING
	}
}